﻿using Newtonsoft.Json;
using ShareRss.Dll;
using ShareRss.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ThunderAgentLib;

namespace ShareRss
{
    public partial class Infos : Form
    {
        public Infos()
        {
            InitializeComponent();
        }

        private void Infos_Load(object sender, EventArgs e)
        {
            //加载文本
            List<Item> Item = JsonConvert.DeserializeObject<List<Item>>(TxtIO.Read($"This_Update_List", "LoveList"));
            //解析文本
            ThisUpdateList.DataSource = Item;
            if (Item != null)
            {
                DataGridViewButtonColumn button = new DataGridViewButtonColumn()
                {
                    UseColumnTextForButtonValue = true,
                    Text = "下载",
                    Width = 50,
                    HeaderText = "下载"
                };
                ThisUpdateList.Visible = true;
                label1.Visible = false;
                ThisUpdateList.Columns[0].HeaderText = "名称";
                ThisUpdateList.Columns[0].Width = 430;
                ThisUpdateList.Columns[2].HeaderText = "更新时间";
                ThisUpdateList.Columns[2].Width = 130;
                ThisUpdateList.Columns[2].DefaultCellStyle.Format = "yyyy-MM-dd HH:mm:ss";
                ThisUpdateList.Columns[7].HeaderText = "类别";
                ThisUpdateList.Columns[7].Width = 60;
                ThisUpdateList.Columns[1].Visible = false;
                ThisUpdateList.Columns[3].Visible = false;
                ThisUpdateList.Columns[4].Visible = false;
                ThisUpdateList.Columns[5].Visible = false;
                ThisUpdateList.Columns[6].Visible = false;
                ThisUpdateList.Columns.Insert(0, button);
            }
            else
            {
                ThisUpdateList.Visible = false;
                label1.Visible = true;
            }
            //展示文字

        }
        private void ThisUpdateList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                DataGridViewRow info = ThisUpdateList.Rows[e.RowIndex];
                AgentClass agent = new AgentClass();
                //AddTask("下载地址", "另存文件名", "保存目录", "任务注释", "引用地址", "开始模式", "只从原始地址下载", "从原始地址下载线程数") 。 
                agent.AddTask(info.Cells["Enclosure"].Value.ToString().Trim(), "index", "C://", "", "", -1, 0, 5);
                agent.CommitTasks2(1);//提交
            }
        }
    }
}
